package lambda_expression.stream;

import lambda_expression.method_reference.Employee;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.function.Function;

public class AllMatchStreamTest {

    public static void main(String[] args) {
        List<Employee> employeeList = new ArrayList<Employee>();
        employeeList.add(new Employee(1, "ABC", 100, 1120.0));
        employeeList.add(new Employee(2, "DEF", 200, 220.0));
        employeeList.add(new Employee(3, "QWE", 300, 330.0));
        employeeList.add(new Employee(4, "RTY", 400, 10.0));
        employeeList.add(new Employee(4, "POI", 200, 10.0));
        employeeList.add(new Employee(4, "UYT", 300, 10.0));

        // allMatch 和 anyMatch是终端操作，只要检测出就会短路：后面的数据就不会执行

        // 断言：所有employee的年龄都大于200
        boolean rst = employeeList.stream()
                .allMatch(employee -> employee.getAge()>200);
        System.out.println("rst = " + rst); // rst = false

        // 断言：是否存在employee年龄大于200的员工
        boolean rst2 = employeeList.stream()
                .anyMatch(employee -> employee.getAge()>200);
        System.out.println("rst2 = " + rst2); // rst2 = true

        // 断言：所有元素都不匹配返回true
        boolean rst3 = employeeList.stream()
                .noneMatch(employee -> employee.getAge()>1200);
        System.out.println("rst3 = " + rst3); // rst3 = true

    }
}
